<html>
<head>
	<meta charset="UTF-8">
	<title>数据源信息表列表</title>
	<link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<link href="../../static/easyui/themes/frameless.css" rel="stylesheet" type="text/css"/>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<script type="text/javascript">

	function doAdd(){
		JLEUtil.createModalWin('新增', 'SSubsDatasourceAdd.html?subsCode='+window.parent.subsCode);
	}

	function doUpdate() {
		var row = $('#dg').datagrid('getSelected');
		if (row){
			JLEUtil.createModalWin('修改', 'SSubsDatasourceUpdate.html?' + 'subsCode=' + row.subsCode + '&subsDsCode=' + row.subsDsCode);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function doDelete(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$.messager.confirm('删除提示', '你确定要删除这条记录?', function(r){
				if (r){
					var jsonData = JSON.parse('{'+'"subsCode":"' + row.subsCode + '"' + ','+'"subsDsCode":"' + row.subsDsCode + '"'+'}');
					$.restfulDelete('../../api/s/subs/datasource', jsonData, function(data) {
						$.messager.alert('提示','记录删除成功!','info');
						$('#dg').datagrid('reload');
					});
				}
			});
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function doConnection(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			var jsonData ={
				subsCode:row.subsCode,
				subsDsCode:row.subsDsCode
			};

			$.restfulPostForm('../../api/dbo/sql/do/connection', jsonData, function(data) {
				$.messager.alert('测试结果：',data.rows,'info');
			});
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function doView(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('详情','SSubsDatasourceView.html?' + '&subsCode=' + row.subsCode + '&subsDsCode=' + row.subsDsCode);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function timedManage() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('自动备份配置信息配置', 'DboBackupConfAdd.html?subsCode='+row.subsCode+"&bpmCode="+row.subsDsCode+"&bpmName="+row.subsDsName);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function startTimedTask(){
		var row = $('#dg').datagrid('getSelected');
		if(row){
			var subsCode = row.subsCode;
			var bpmCode=row.subsDsCode+"_MysqlBackup";
			var bpmName=row.subsDsName+"定时备份服务";
			var bpmType = 1;
			var queryParams={
				subsCode: subsCode,
				bpmCode:bpmCode,
				bpmName:bpmName
			};
			var rows;
			$.restfulPostForm('../../api/bpm/base/infos/'+bpmType, queryParams, function(data){
				if(data.rows.length==0)
					$.messager.alert('提示','该自动流程不存在！','info');
				else {
					for(var i=0;i<data.rows.length;i++)
						if(data.rows[i].latestState=="Y")
							rows=data.rows[i];
				}
			});
			if (rows) {
				if (rows.bpmState=='1') {
					if(confirm("是否确认要手工发起流程？")){
						var params = {
							bpaSerialNo: 'none',
							bpaId: rows.bpmId,
							bpmCode:rows.bpmCode,
							batchAction:'run',
							bpmVersion: rows.bpmVersion
						}
						$.restfulGet('../../api/bat/batch/info/action/', params, function(data){
							if(data.code == '0') {
								$.messager.alert('提示', data.message,'success');
							} else {
								$.messager.alert('提示', data.message,'error');
							}
						},function (data) {
							$.messager.alert('提示', data.message,'error');
						});
					}
				}else{
					$.messager.alert('提示','该流程还未发布，请先发布流程！','info');
				}
			} else {
				$.messager.alert('提示','自动流程不存在或者已经发布新版本！','info');
			}
		}else{
			$.messager.alert('提示','请选择一条数据！','info');
		}
	}

	function dataModifyWindow(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			var url = 'TableNameList.html?subsCode='+row.subsCode+'&subsDsCode='+row.subsDsCode;
			JLUtil.linkNewPage(url);
		}else{
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function dataModifyLog(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('详情','DboSqlLogList.html?dsCode='+row.subsCode);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function reloadList(){
		$('#dg').datagrid('reload');
		JLEUtil.closewin();
	};
</script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',title:''" style="height: 40px; ">
	<form id="searchForm">
		<table>
			<tr>
				<td class="searchTd">&nbsp;数据源代码：</td>
				<td><input name="subsDsCode" id="subsDsCode"/></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.queryForm('searchForm','dg','../../api/s/subs/datasources');">查找</a></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.clearForm('searchForm');">清空</a></td>
			</tr>
		</table>
	</form>
</div>
<div data-options="region:'center',split:false">
	<table id="dg" class="easyui-datagrid" title="" style="width:100%;height:95%"
		   data-options="singleSelect:true,collapsible:true,url:'../../api/s/subs/datasources/'+window.parent.subsCode,method:'post'"
		   toolbar="#tb"
		   title="Load Data"
		   rownumbers="true" pagination="true" pageSize="20">
		<thead>
		<tr>
			<th data-options="field:'subsCode',resizable:true" >业务系统代码</th>
			<th data-options="field:'subsDsCode',resizable:true" >数据源代码</th>
			<th data-options="field:'subsDsName',resizable:true" >数据源名称</th>
			<th data-options="field:'dsConnStr',resizable:true" >数据源-连接字符串</th>
			<th data-options="field:'dsUserId',resizable:true" >数据源-用户名</th>
			<th data-options="field:'dsUserPwd',resizable:true,hidden:true" >数据源-用户密码</th>
			<th data-options="field:'dsSchemaName',resizable:true" >数据源-模式</th>
			<th data-options="field:'dsDbName',resizable:true" >数据源-数据库名</th>
			<th data-options="field:'subsDsType',resizable:true" formatter="formatter_S_SUBS_DS_TYPE">数据源类型</th>
		</tr>
		</thead>
	</table>
</div>
<div id="tb" style="padding:1px">
	<div style="margin-bottom:2px">
		<a href="#" class="easyui-menubutton" data-options="menu:'#dataSourceMenu',iconCls:'icon-tip'" plain="true">数据源管理</a>
		<a href="#" class="easyui-menubutton" data-options="menu:'#dataModifyMenu',iconCls:'icon-tip'" plain="true">数据修改管理</a>
		<a href="#" class="easyui-menubutton" data-options="menu:'#dataBackupMenu',iconCls:'icon-tip'" plain="true">数据备份管理</a>
	</div>
</div>
<div id="dataBackupMenu" style="width:120px;">
	<div onclick="javascript:timedManage()">自动备份配置</div>
	<div onclick="javascript:startTimedTask()">执行自动备份</div>
</div>
<div id="dataModifyMenu" style="width:120px;">
	<div onclick="javascript:dataModifyWindow()">数据修改窗口</div>
	<div onclick="javascript:dataModifyLog()">数据修改日志</div>
</div>
<div id="dataSourceMenu" style="width:120px;">
	<div onclick="javascript:doAdd()">新增数据源</div>
	<div onclick="javascript:doUpdate()">修改数据源</div>
	<div onclick="javascript:doDelete()">删除数据源</div>
	<div onclick="javascript:doView()">查看数据源</div>
	<div onclick="javascript:doConnection()">连接测试</div>
</div>
</body>
</html>
